From 4838df315931bb883f704ec3e1abe2685f296cdf Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sat, 22 Apr 2023 19:52:26 +0800 Subject: 😀 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/pages/api/user/[id].tsx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docs/pages/api/user/[id].tsx (limited to 'docs/pages/api/user/[id].tsx') diff --git a/docs/pages/api/user/[id].tsx b/docs/pages/api/user/[id].tsx new file mode 100644 index 0000000..091d716 --- /dev/null +++ b/docs/pages/api/user/[id].tsx @@ -0,0 +1,36 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import { withSentry } from "@sentry/nextjs"; +import { + getSubscriber, + Subscriber, + updateSubscriber, +} from "../../../lib/ConvertKitApi"; + +async function handler(req: NextApiRequest, res: NextApiResponse) { + try { + if (req.method === "PUT") { + const subscriber = await updateSubscriber( + req.query.id as string, + { + first_name: req.body.first_name, + email_address: req.body.email_address, + fields: req.body.fields, + } as Subscriber + ); + res.setHeader("Content-Type", "application/json"); + res.statusCode = 204; + res.json(subscriber); + } else { + const subscriber = await getSubscriber(req.query.id as string); + res.setHeader("Content-Type", "application/json"); + res.statusCode = 200; + res.json(subscriber); + } + } catch (error) { + console.log(error); + res.statusCode = 500; + res.json({ okay: false }); + } +} + +export default withSentry(handler); -- cgit v1.2.3-70-g09d2